<template>
    <view class="content" v-if="isShow">
        <view class="title text-lg">基础信息</view>
        <view class="box text-noraml">
            <view class="item">
				<view v-if="type == 3">单号</view>
                <view v-else>{{ data.type == 1 ? '采购单号' : '销退单号' }}</view>
                <view class="item-r text-bold">{{data.belong}}</view>
            </view>
            <view class="item">
                <view>{{ data.type == 1 ? '供货企业' : '退货企业' }}</view>
                <view class="item-r text-bold">{{data.company}}</view>
            </view>
            <view class="item">
                <view>{{ data.type == 1 ? '供货企业销售人员' : '退货企业采购人员' }}</view>
                <view class="item-r text-bold">{{data.account}}</view>
            </view>
            <view class="item-img" v-if="data && data.agreement && data.agreement.length > 0">
                <view>供货企业随行同行单</view>
                <view class="item-img-down">
                    <image v-for="(el, ind) in data.agreement" :key="ind" :src="el.value" 
                        class="img" @click="$previewImage(data.agreement, ind)"></image>
                </view>
            </view>
        </view>
        
        <view class="title text-lg">药品信息</view>
        <view class="wrapper">
            <view class="drug text-noraml" v-for="(item, index) in data.goods_list" :key="index">
                <view class="drug-name text-bold">{{item.goods_name}}</view>
                <view class="drug-down-l text-df text-gray">
                    <view class="u-p-t-15" v-if="item.dosage">剂型：{{item.dosage}}</view>
                    <view class="u-p-t-15">规格：{{item.goods_spec}}</view>
                    <view class="u-p-t-15">生产厂商：{{item.factory}}</view>
                    <view class="u-p-t-15">批号：{{item.batch}}</view>
                    <view class="u-p-t-15">生产日期：{{item.produce_date}}</view>
                    <view class="u-p-t-15">有效日期：{{item.period_date}}</view>
                    <view class="u-p-t-15">到货日期：{{item.take_time}}</view>
                    <view class="u-p-t-15">采购数量：{{item.goods_nums}}</view>
                    <view class="u-p-t-15">到货数量：{{item.take_nums}}</view>
					<!-- 向下取整 -->
					<view class="u-p-t-15" v-if="item.scaler_num">
						件数：{{ Math.floor(item.goods_nums / item.scaler_num) }}
					</view>
					
					
                    <!-- 一次验收 -->
                    <template v-if="item.second_check_nums <= 0">
                        <view class="u-p-t-15">验收合格数量：{{item.check_nums}}</view>
                        <template v-if="item.quality_uri && item.quality_uri.length > 0">
                            <view class="u-p-t-15">质检单：</view>
                            <view class="item-img-down">
                                <image v-for="(el, ind) in item.quality_uri" :key="ind" :src="el.value" 
                                    class="img" @click="$previewImage(item.quality_uri, ind)"></image>
                            </view>
                        </template>
                    </template>
                    <!-- 二次验收 -->
                    <template v-if="item.second_check_nums > 0">
                        <view class="u-p-t-15">验收合格数量：{{item.second_check_nums}}</view>
                        <template v-if="item.second_quality_uri && item.second_quality_uri.length > 0">
                            <view class="u-p-t-15">质检单：</view>
                            <view class="item-img-down">
                                <image v-for="(el, ind) in item.second_quality_uri" :key="ind" :src="el.value" 
                                    class="img" @click="$previewImage(item.second_quality_uri, ind)"></image>
                            </view>
                        </template>
                    </template>
                </view>
                <view class="place text-df text-gray" v-if="type == 2 && order_status == 4">
                    <view class="u-p-t-15">库位：{{item.stores_house}}</view>
                    <view class="u-p-t-15">货位：{{item.library}}</view>
                    <view class="u-p-t-15">托盘：{{item.tray}}</view>
                </view>
                <view class="enter-btn" v-if="type == 1 && item.status != 3">
                    <view @click.stop="enter(item)">入库</view>
                </view>
            </view>
        </view>
        
        <template v-if="type == 2 && order_status == 4">
            <view class="title text-lg">审核信息</view>
            <view class="examine text-df text-gray">
                <view class="u-p-t-15">收货人：{{data.take_member}}</view>
                <view class="u-p-t-15">收货时间：{{data.take_time}}</view>
                <view class="u-p-t-15">验收人：{{data.check_member}}</view>
                <view class="u-p-t-15">验收时间：{{data.check_time}}</view>
                <view class="u-p-t-15">入库人：{{data.member}}</view>
                <view class="u-p-t-15">入库时间：{{data.create_time}}</view>
            </view>
        </template>
        
        <view class="btn-square u-m-30" v-if="type == 1" @click="$noMultipleClicks(doSubmit)">确认入库</view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                noClick: true,//连点
                isShow: false,
                type: '',
                order_status: '',
                id: '',
                data: {},
            };
        },
        onLoad(option) {
            if (option.type == 2 && option.order_status == 3) {
                uni.setNavigationBarTitle({
                	title:'已验收'
                })
            }
			if (option.type == 3) {
			    uni.setNavigationBarTitle({
			    	title:'拒收'
			    })
			}
            this.type = option.type
            this.order_status = option.order_status
            this.id = option.id
        },
        onShow() {
            this.getData()
        },
        methods: {
			// 入库
			enter(item) {
				// 带默认stores_house stores_house_id库区，可以修改
				let check_nums //验收合格数量
				if (item.second_check_nums <= 0) {
					check_nums = item.check_nums
				} else {
					check_nums = item.second_check_nums
				}
				this.$gTo(`/pages/enter-record/choose-house?id=${this.id}&goods_id=${item.id}&stores_house=${item.stores_house}&stores_house_id=${item.stores_house_id}&check_nums=${check_nums}&scaler_num=${item.scaler_num}`)
			},
			
            doSubmit() {
                let isNull = false
                this.data.goods_list.forEach(cur => {
                    // status = 3是已入库。其他 的未入库。
                    if (cur.status != 3) {
                        isNull = true
                    }
                })
                if (isNull) {
                    this.$toast('有未入库的药品，请先入库！');
                    return
                }
                
                this.$ajax('inventory_put/ack_put', {
                    userToken: this.$getSync('userToken'),
                    check_id: this.id,
                    memo: '',//备注
                }).then(ret => {
                	if (ret.status == 0) {
                        this.$toast('提交成功');
                        setTimeout(() => {
                            this.$backT()
                        }, 500)
                	} else {
                		this.$toast(ret.message);
                	}
                });
            },
            
            // order_status = 0未收货 1-已收货,待验收  2-已验收,待二次验收  3-已二次验收  4-已入库
            getData() {
                let url = ''
                if (this.order_status == 4) {
                    // 已入库 详情
                    url = 'inventory_put/put_detail'
                } else {
                    // 已验收 待入库 详情
                    url = 'inventory_put/check_detail'
                }
            	this.$ajax(url, {
                    userToken: this.$getSync('userToken'),
                    id: this.id, //收货订单编号
                }).then(ret => {
            		if (ret.status == 0) {
                        this.data = ret.data
                        
                        this.isShow = true
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f5f5f5 !important;
    }
    .title{
        font-weight: bold;
        padding: 45rpx 50rpx 25rpx;
        position: relative;
    }
    .title::after{
        display: block;
        content: '';
        width: 8rpx;
        height: 26rpx;
        background-color: #ff4800;
        position: absolute;
        left: 25rpx;
        bottom: 32rpx;
    }
    
    
    .box{
        padding: 0 30rpx;
        background-color: #fff;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx 0;
        border-bottom: 2rpx solid #e6e6e6;
    }
    .item:last-child{
        border-bottom: none;
    }
    .item-r{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
        text-align: right;
        padding-left: 20rpx;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .item-img{
        padding: 30rpx 0;
    }
    .item-img-down{
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
    }
    .img{
        width: 316rpx;
        height: 200rpx;
        border-radius: 10rpx;
        margin-top: 20rpx;
        margin-right: 20rpx;
    }
    .img:nth-child(2n) {
        margin-right: 0;
    }
    
    
    .drug{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 35rpx 15rpx;
        margin-bottom: 25rpx;
    }
    .drug:last-child{
        margin-bottom: 0;
    }
    .drug-top{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .drug-name{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
        padding-left: 15rpx;
    }
    .drug-state1{
        font-size: 24rpx;
        color: #0075ff;
        padding: 9rpx 12rpx;
        background-color: #ebf4fe;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }
    .drug-state2{
        font-size: 24rpx;
        color: #00c28f;
        padding: 9rpx 12rpx;
        background-color: #e9fbf6;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }
    .drug-down{
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
    }
    .drug-down-l{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
        padding-bottom: 30rpx;
        padding-left: 15rpx;
        padding-right: 15rpx;
    }
    .drug-btn{
        color: #fff;
        padding: 17rpx 43rpx;
        background-color: #ff4800;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }
    
    
    .examine{
        word-break: break-all;
        white-space: pre-line;
        padding: 15rpx 25rpx 30rpx;
        background-color: #fff;
        border-radius: 15rpx;
        margin: 0 30rpx 25rpx;
    }
    .t-inp{
        width: 100%;
        min-height: 150rpx;
        height: auto;
        padding-top: 15rpx;
    }
    .examine2{
        padding: 15rpx 0;
    }
    .img-box{
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
    }
    .up-photo{
        width: 187rpx;
        height: 187rpx;
        margin-right: 15rpx;
        margin-top: 15rpx;
    }
    
    
    .btns{
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 30rpx;
    }
    .refuse-btn{
        font-size: 34rpx;
        color: #757575;
        padding: 25rpx 130rpx;
        background-color: #fff;
        border: 2rpx solid #d8d8d8;
        border-radius: 10rpx;
    }
    .take-btn{
        font-size: 34rpx;
        color: #fff;
        padding: 25rpx 130rpx;
        background-color: #ff4800;
        border-radius: 10rpx;
        margin-left: 20rpx;
    }
    
    .enter-btn{
        display: flex;
        justify-content: flex-end;
        align-items: center;
        padding-top: 10rpx;
    }
    .enter-btn>view{
        padding: 15rpx 50rpx;
        background-color: #8392a5;
        border-radius: 10rpx;
        color: #fff;
    }
    
    .place{
        word-break: break-all;
        white-space: pre-line;
        padding: 5rpx 20rpx 20rpx;
        background-color: #f5f6f8;
        border-radius: 10rpx;
    }
    .wrapper{
        padding: 0 30rpx;
    }
    .choose-01{
        width: 33rpx;
        height: 33rpx;
        margin-right: 15rpx;
    }
    .time-02{
        width: 33rpx;
        height: 34rpx;
        margin-left: 15rpx;
    }

</style>
